package com.example.demo.annotation;

import com.example.demo.Constants;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "helloWebServlet", value = "/hello-web-servlet")
public class HelloWebServlet extends HttpServlet {
    private String message;

    @Override
    public void init() {
        message = String.format(Constants.HELLO_TEMPLATE, "WebServlet");
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");

        // Hello
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<h1>" + message + "</h1>");
        out.println("</body></html>");
    }

}